package com.example.baiduai.hander.impl;

import com.example.baiduai.dto.AiDto;
import com.example.baiduai.hander.PayMannerHander;
import com.example.baiduai.interfaces.Constat;
import com.example.baiduai.utils.GooGleCacheUtils;
import com.example.baiduai.utils.ObjectUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 现金支付 2
 */
@Component
public class CashPayImpl extends PayMannerHander implements InitializingBean {

    @Autowired
    CashRegistersOpenImpl cashRegistersOpenImpl;

    @Override
    public String  payMannerStatus(AiDto dto) {
        if(dto.getLabelNames().contains("现金支付")){
            Boolean b = GooGleCacheUtils.isCashPayCache(Constat.prefix.CASH_PAY_PREFIX + dto.getDevice_id());

             //
            if(ObjectUtils.isEmpty(b)){ //现金支付
                // 加入缓存
                GooGleCacheUtils.cashPayCachePut(Constat.prefix.CASH_PAY_PREFIX + dto.getDevice_id());


                return "现金支付加入缓存成功";
            }else return "现金支付还在进行中"; //

        }else return cashRegistersOpenImpl.payMannerStatus(dto);
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        this.setPayHander(cashRegistersOpenImpl);
    }
}
